package com.santana.parser.googleMovie;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import net.htmlparser.jericho.Attribute;
import net.htmlparser.jericho.Attributes;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Source;
import net.htmlparser.jericho.StartTag;

import org.apache.log4j.Logger;

public class HTMLParser {

	private static Logger log = Logger.getLogger(HTMLParser.class);

	public List<String> getElements(URL url, String elementType,
			String elementName) throws IOException {
		
		log.info("Parsing "+url);

		List<String> movies = new ArrayList<String>();

		Source source = new Source(url);
		List<Element> divs = source.getAllElements("div");

		for (Element element : divs) {

			StartTag startTag = element.getStartTag();
			Attributes attributes = startTag.getAttributes();

			for (Attribute atribute : attributes) {

				if (atribute.getName().compareTo("class") == 0) {

					if (atribute.getValue().compareTo("movie") == 0) {
						movies.add(element.getTextExtractor().toString());
					}
				}
			}
		}

		return movies;
	}
}
